package com.mijie.tag;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import javax.el.ELContext;
import javax.el.ELResolver;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.mijie.core.ApplicationProperties;

public class SwitchTag extends SimpleTagSupport{
	private String category;
	private String value;
	private String defaultValue;
	
	public void doTag() throws JspException, IOException {
		Map<String,String> map = ApplicationProperties.getXmlConf(category);
		if(map==null || map.isEmpty()) return;
		JspWriter out = getJspContext().getOut();
		if(map.get(value)!=null){
			out.write(map.get(value));
		}else{
			if(defaultValue!=null) 
				out.write(defaultValue);
		}
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public void setDefault(String defaultValue){
		this.defaultValue = defaultValue;
	}
}
